#include<iostream>
#include<cstring>
using namespace std;
const int N = 1e4 + 10, M = 1e5 + 10;
int mp[N][N];
int dis[N];
int st[N];
int w[N];
int n, m, t;
int ans;
void dij()
{
	memset(dis, 0x3f, sizeof(dis));
	dis[1] = 0;
	for (int i = 0; i < n; i++) {
		int k = -1;
		for (int j = 1; j <= n; j++) {
			if (!st[j] && (t == -1 || dis[t] > dis[j])) {
				k = j;
			}
		}
		st[k] = 1;
		for (int j = 1; j <= n; j++) {
			dis[j] = min(dis[j], dis[t] + mp[k][j]);
		}
	}
}
int main()
{
	cin >> n >> m >> t;
	for (int i = 1; i <= n; i++) {
		cin >> w[i];
	}
	for (int i = 1; i <= m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		mp[a][b] = mp[b][a] = min(mp[a][b], c);
	}
	dij();
	cout << dis[n] << endl;
	return 0;
}